﻿cmake_minimum_required(VERSION 3.10)

# 在project命令之前设置vcpkg工具链
set(CMAKE_TOOLCHAIN_FILE "C:/WorkSpace/source/oss/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")

# 设置使用静态库
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")

project(UDPReceiver VERSION 1.0.0.0)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置MSVC运行时库为静态链接
if(MSVC)
    # 明确设置：Release使用/MT，Debug使用/MTd
    set(CMAKE_MSVC_RUNTIME_LIBRARY 
        "$<$<CONFIG:Debug>:MultiThreadedDebug>$<$<CONFIG:Release>:MultiThreaded>"
    )
endif()

# 定义 Windows 版本 (Windows 10)
add_compile_definitions(_WIN32_WINNT=0x0A00)

# 如果支持，请为 MSVC 编译器启用热重载。
if (POLICY CMP0141)
  cmake_policy(SET CMP0141 NEW)
  set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

# 查找 Asio 依赖
set(asio_DIR "C:/WorkSpace/source/oss/vcpkg/packages/asio_x64-windows/share/asio")
find_package(asio CONFIG REQUIRED)

# 将源代码添加到此项目的可执行文件。
add_executable (UDPReceiver "src/udpreceiver.cpp" "src/udpreceiver.h")

if (CMAKE_VERSION VERSION_GREATER 3.12)
  set_property(TARGET UDPReceiver PROPERTY CXX_STANDARD 20)
endif()

# 链接依赖库
target_link_libraries(UDPReceiver PRIVATE asio::asio)